//
// Created by amon.huang on 2021/7/28.
//

#ifndef AMONPLAYER_MEDIABASE_H
#define AMONPLAYER_MEDIABASE_H

#include "JNICall.h"
#include "PacketQueue.h"
#include "PlayerStatus.h"

#ifdef __cplusplus
extern "C" {
#endif

#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavcodec/avcodec.h>

#ifdef __cplusplus
}
#endif

class MediaBase {
public:
    int streamIndex = -1;
    AVCodecContext *pCodecContext = NULL;
    JNICall *pJniCall;
    PacketQueue *pPackQueue;
    PlayerStatus *pPlayerStatus;

    double currentTime = 0;
    double lastUpdateTime = 0;
    double duration = 0;

    AVRational timeBase;
public:
    MediaBase(int streamIndex, JNICall *pJNICall, PlayerStatus *pPlayerStatus);

    ~MediaBase();

    virtual void play() = 0;

    virtual void pause() = 0;

    void analysisStream(ThreadMode threadMode, AVFormatContext *pFormatContext);

    void analysisStreamCommon(ThreadMode threadMode, AVFormatContext *pFormatContext);

    virtual void release();

protected:
    void callPlayJniError(ThreadMode threadMode, int code, char *msg);

private:
    virtual void analysisStreamInner(ThreadMode threadMode, AVFormatContext *pFormatContext) = 0;
};


#endif //AMONPLAYER_MEDIABASE_H
